package com.mygdx.game.Stage;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.mygdx.game.Scenes.ActiveCharacter;
import com.mygdx.game.Scenes.ActiveCharacter_Pope;
import com.mygdx.game.Screens.PlayScreen;

public class StartStage extends Stage {
    public static final Rectangle rectangleA = new Rectangle();
    public static final Rectangle rectangleB = new Rectangle();

    private String background;
    private Texture textureStart;
    private TextureRegion startRegion;
    private Image startImage;
    private ActiveCharacter activeCharacter;
    private ActiveCharacter_Pope activeCharacter_pope;


    public StartStage(String background) {
        super();
        this.background = background;
        init();
    }

    private void init() {
        textureStart = new Texture(Gdx.files.internal(background)); //"GroupProject/image/story.png"
        startRegion = new TextureRegion(textureStart, 0, 0, 1000, 1080);
        startImage = new Image(startRegion);
        startImage.setSize(1920, 1080);
        activeCharacter = new ActiveCharacter("Character/GreenNPC",600 ,600);
        activeCharacter_pope = new ActiveCharacter_Pope(600,200);

        this.addActor(startImage);
        this.addActor(activeCharacter);
        this.addActor(activeCharacter_pope);

    }
    public void Check(){
        checkCollision(activeCharacter,activeCharacter_pope);
    }
    private void checkCollision(ActiveCharacter A, ActiveCharacter_Pope B) {
        rectangleA.set(
                A.x,
                A.y,
                A.width/3,
                A.heigth/3
        );
        rectangleB.set(
                B.x,
                B.y,
                B.width/3,
                B.heigth/3
        );
        if (rectangleA.overlaps(rectangleB)) {
            System.out.println("撞上了");
            PlayScreen.flag = 3;
            activeCharacter.Collision=true;
            A.getColor().a = 0.1F;
        } else {
            activeCharacter.Collision=false;
            A.getColor().a = 1.0F;
        }
    }
}
